package com.app.business.show;

import com.app.business.model.AzProject;
import com.app.business.model.House;
import com.app.business.service.*;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 手机公示（没有权限限制）
 * Created by DDZ on 2023/10/10.
 */
@Controller
@RequestMapping("/showForJyApp/*")
@SuppressWarnings("all")
public class ShowForJyAppController {
    @Autowired
    private ContractService contractService;
    @Autowired
    private ZsProjectService zsProjectService;
    @Autowired
    private AzProjectService azProjectService;
    @Autowired
    private DataDictService dataDictService;
    @Autowired
    private HouseService houseService;
    @Autowired
    private CarLotService carLotService;
    @Autowired
    private StorageRoomService storageRoomService;
    @Autowired
    private StatisticsService statisticsService;
    @Autowired
    private ShowHjService showHjService;

    /**
     * 大屏主界面
     */
    @RequestMapping("showForBuildNum")
    public void showForBuildNum(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "156");

        Map<String, List<String>> azProjectNameAndBuildNumMap = this.showHjService.getBuildNumMapByAzProjectName(zsProjectIdStr);
        List<AzProject> azProjectList = this.azProjectService.getAzProjectListByZsProjectIdStr(zsProjectIdStr);
        modelMap.addAttribute("azProjectNameAndBuildNumMap", azProjectNameAndBuildNumMap);
        modelMap.addAttribute("azProjectList", azProjectList);
    }

    /**
     * 柱状图
     */
    @RequestMapping("showForHouse")
    public void houseZhuShow(HttpServletRequest request, ModelMap modelMap) {
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        AzProject azProject = this.azProjectService.findOne(azProjectId);
        modelMap.addAttribute("buildNum", buildNum);
        modelMap.addAttribute("azProject", azProject);

    }

    /**
     * 楼盘图
     *
     * @param request
     */
    @RequestMapping("showForHousePic")
    public void showForHousePic(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "156");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        //通过征收项目、安置项目、楼号得到所分配的houseList
        List<House> houseList = houseService.houseList(zsProjectIdStr, azProjectId, buildNum);
        //得到层号和当前楼层的List<House>对应的map
        Map<String, Map<String, House>> floorAndHouseNumForHouseMap = houseService.getFloorAndHouseNumMap(houseList);
        //获取当前安置项目最高层
        Map<String, Integer> maxFloorMap = houseService.getMaxFloorMap(zsProjectIdStr, azProjectId, buildNum);
        Integer maxFloor = maxFloorMap.get("maxFloor");
        Integer maxHouseNum = maxFloorMap.get("maxHouseNum");
        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("房源状态");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");

        modelMap.addAttribute("buildNum", buildNum);
        modelMap.addAttribute("floorAndHouseNumForHouseMap", floorAndHouseNumForHouseMap);
        modelMap.addAttribute("maxFloor", maxFloor);
        modelMap.addAttribute("rowNum", Math.round(maxHouseNum / 10) == 0 ? 1 : Math.round(maxHouseNum / 10));
        modelMap.addAttribute("maxHouseNum", maxHouseNum);
        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
    }
}
